@echo off
:: ----------------------------------------------------------------------------
:: Initial values; these can be overwritten in user.bat
:: ----------------------------------------------------------------------------
set dllModule=
set loaderDirectory=Release/
set loaderName=AIModuleLoader.exe
set starcraftPath=..


:: ----------------------------------------------------------------------------
:: user.bat Data
:: ----------------------------------------------------------------------------
:: If there is a user.bat data file in this folder, execute it to set some parameters
if exist "user.bat" (
	call "user.bat"
)


:: ----------------------------------------------------------------------------
:: Auto-detect DLL Module
:: ----------------------------------------------------------------------------
:: If the dll module is not specified, check the argument that was passed first
:: We're checking in Release and relatively, with and without .dll
if "%dllModule%" == "" if not "%1" == "" (
	if exist "Release/%1" 			set dllModule="Release/%1"
	if exist "Release/%1.dll" 		set dllModule="Release/%1.dll"
	if exist "%1" 					set dllModule="%1"
	if exist "%1.dll" 				set dllModule="%1.dll"
)
:: If no parameter was passed, look in the Release folder for any we can find
if "%dllModule%" == "" (
	for /F "tokens=1 delims=" %%a in ('dir /b Release\*.dll') do set dllModule=%%a
)


:: ----------------------------------------------------------------------------
:: Kill the task (silently) and start a new one
:: ----------------------------------------------------------------------------
taskkill /IM %loaderName% > NUL 2> NUL
start /D"%starcraftPath%" %loaderDirectory%%loaderName% %dllModule%
echo Starting Module Loader with %dllModule%

